var app = getApp();
import { config } from '../../../utils/config'
import util from '../../../utils/util'
import api from '../../../utils/api.js'

/*
类型 （1自由兑换区，2天使体验区）
排序方式 （1综合，2价格降序，3价格升序，4评***价）
*/

// pages/pointsMall/pointsDetail/pointsDetail.js
Page({

    /**
     * Page initial data
     */
    data: {
        imgUrl: config.imgUrl,
        searchObj: {
            placeStr: '请输入商品名称',
            searchWidth:'488rpx'
        },
        priceOrder: 1, //默认排序
        inputValue: '',
        page: 1,
        productList: [],
        

    },

    /**
     * Lifecycle function--Called when page load
     */
    onLoad: function(options) {

        // 判断用户是否是会员身份
        let is_member = wx.getStorageSync('is_member');
        this.setData({
            is_member
        })

        this.integralList();

    },
    /*获取列表内容*/
    integralList() {
        let data = {
            type: 2,
            order: this.data.priceOrder,
            keyword: this.data.inputValue,
            page: this.data.page
        };
        util.getInfo(api.integralList, 'GET', data).then(res => {
            this.setData({
                last_page: res.last_page,
                productList: this.data.productList.concat(res.data)
            })

        })

    },
    /*搜索按钮*/
    searchHandle(e) {
        let inputValue = e.detail.inputValue
            // 请求排序

        // if (inputValue == '') {
        //     this.setData({
        //         inputValue: ''
        //     })
        // } else {
            
        // }
        this.setData({
            inputValue,
            productList: [],
            page: 1
        })
        this.integralList();


    },
    /*价格排序*/
    priceOrder(e) {
        let priceOrder = e.currentTarget.dataset.order;
        
        // 请求排序
        this.setData({
            priceOrder,
            productList: [],
            page: 1
        })

        this.integralList();

    },

    toDetail(e) {
        let id = e.currentTarget.dataset.id;
        let type = e.currentTarget.dataset.type;
        wx.navigateTo({
            url: `/pages/pointsMall/details/details?id=${id}&type=${type}`
        })
    },

    /**
     * Lifecycle function--Called when page is initially rendered
     */
    onReady: function() {

    },

    /**
     * Lifecycle function--Called when page show
     */
    onShow: function() {

    },

    /**
     * Lifecycle function--Called when page hide
     */
    onHide: function() {

    },

    /**
     * Lifecycle function--Called when page unload
     */
    onUnload: function() {

    },

    /**
     * Page event handler function--Called when user drop down
     */
    onPullDownRefresh: function() {

    },

    /**
     * Called when page reach bottom
     */
    onReachBottom: function() {
        console.log('触底刷新');
        if (this.data.page < this.data.last_page) {
            this.setData({
                page: this.data.page + 1
            })
            this.integralList();
        }
    },

    /**
     * Called when user click on the top right corner to share
     */
    onShareAppMessage: function() {

    }
})